//
// Created by 王乐 on 2022/2/10.
//

#include "LeMoveShadowRenderer.h"
#include "glad/glad.h"

#include "LeVBOManager.h"
#include "LeUtils.h"

#include "LeCameraManager.h"

#include "LeTransform.h"

#include "glm/gtc/matrix_transform.hpp"

#include "LeParticleBehaviour.h"

void LeMoveShadowRenderer::render()
{
    if(!m_GameObject->isActive())
        return;

    glm::mat4 projection =  LeCameraManager::getProjectionMatrix();
    glm::mat4 view = LeCameraManager::getViewMatrix();

    // be sure to activate shader when setting uniforms/drawing objects
    m_Shader.useShader();

    m_Shader.setFloat("alphaValue", dynamic_cast<LeParticleBehaviour*>(m_GameObject->m_pBehaviour) ->m_AlphaValue);
    m_Shader.setFloat("rValue", dynamic_cast<LeParticleBehaviour*>(m_GameObject->m_pBehaviour) ->m_RValue);

    m_Shader.setMat4("projection", projection);
    m_Shader.setMat4("view", view);

    glm::mat4 model = m_GameObject->m_Transform.getModelMatrix();
    model = glm::scale(model, glm::vec3(1.03f, 1.03f, 1.0f));
    m_Shader.setMat4("model", model);

    m_Shader.setInt("material.diffuse", 0);
    // bind diffuse map
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, diffuseMap);

    // render the cube
    glBindVertexArray(VAO);
    glDrawArrays(GL_TRIANGLES, 0, 6);
}

LeMoveShadowRenderer::LeMoveShadowRenderer()
{}

LeMoveShadowRenderer::~LeMoveShadowRenderer()
{

}
